package org.wanho.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2023-04-24 13:40
 * Description：<描述>
 */
@WebServlet("/session")
public class SessionServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();

        session.setMaxInactiveInterval(600); // 设置有效期10分钟

        System.out.println(session.getId());
        System.out.println(session);

        session.setAttribute("username","tom");
        session.setAttribute("address","南京");

        System.out.println(session.getAttribute("username"));

        session.removeAttribute("address");


    }
}
